import path from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import Pages from "vite-plugin-pages";

import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import ElementPlus from "unplugin-element-plus/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

export default defineConfig({
	resolve: {
		alias: {
			"@/": `${path.resolve(__dirname, "src")}/`,
		},
	},
	base: "/kanacard/",
	plugins: [
		vue(),
		Pages({
			dirs: "src/views",
		}),
		ElementPlus(),
		AutoImport({
			resolvers: [ElementPlusResolver()],
		}),
		Components({
			resolvers: [ElementPlusResolver()],
		}),
	],
	server: {
		proxy: {
			"/api": {
				changeOrigin: true,
				target: "http://localhost:4000",
				rewrite: (path) => path.replace(/^\/api/, ""),
			},
		},
	},
});
